package com.itheima.controller.v1;

import com.alibaba.fastjson.JSON;
import com.itheima.common.R;
import com.itheima.controller.v1.api.BusinessControllerApi;
import com.itheima.dto.ClueQueryDto;
import com.itheima.pojo.TbBusiness;
import com.itheima.pojo.TbBusinessTrackRecord;
import com.itheima.pojo.TbClue;
import com.itheima.service.TbBusinessService;
import com.itheima.service.TbBusinessTrackRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business")
@Slf4j
public class BusinessController implements BusinessControllerApi {
    @Autowired
    private TbBusinessService tbBusinessService;

    @Autowired
    private TbBusinessTrackRecordService tbBusinessTrackRecordService;

    @GetMapping("/businessPage")
    @Override
    public R businessPage(@RequestBody ClueQueryDto clueQueryDto) {
        if (clueQueryDto.getPageSize()==null) {
            return R.error("请求参数为空,请输入请求参数clueQueryDto");
        }
        log.info("分页clueQueryDto{}",clueQueryDto);
        return tbBusinessService.page(clueQueryDto);
    }

    @Override
    @PostMapping
    public R add(@RequestBody TbBusiness tbBusiness) {
        return tbBusinessService.insertBusiness(tbBusiness);
    }

    @Override
    @GetMapping("/{id}")
    public R businessSimple(@PathVariable Long id) {
        return tbBusinessService.getById(id);
    }

    @Override
    @GetMapping("/getTrackList/{businessId}")
    public R getBusinessTrackRecordById(@PathVariable String businessId) {
        return tbBusinessTrackRecordService.getByBusinessId(businessId);
    }

    @Override
    @PutMapping
    public R updateBusiness(@RequestBody  TbBusiness tbBusiness) {
        return tbBusinessService.update(tbBusiness);
    }

    @Override
    @PostMapping("/track")
    public R addBusinessTrackRecord(@RequestBody TbBusinessTrackRecord tbBusinessTrackRecord) {
        return tbBusinessTrackRecordService.add(tbBusinessTrackRecord);
    }

    @Override
    @PutMapping("/status/{id}")
    public R updateBusyStatus(@PathVariable Long id, String status) {
        return tbBusinessService.updateStatus(id,status);
    }
}
